'''

@author: Chris
'''
import en

class SentenceGrammar(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        pass
    
    def checkChunks(self, chunks):
            return self.sentence(chunks)
            
        
    def sentence(self, chunks):
        try:
            if (self.subjectPhrase(chunks[0])):
                if (len(chunks) > 1):
                    if(chunks[1][0] == "PP"):
                        pass
                    elif(chunks[1][1] == "IN"):
                        if(self.verbPhrase(chunks[2])):
                            pass
                        else:
                            return False
                    else:
                        return False
            else:
                return False
                
        
        except IndexError:
                return False
            
        return True
            
    def subjectPhrase(self, chunk):
        if (chunk[1][0] == "NP"):
            if(self.nounPhrase(chunk[1])):
                pass
            else:
                return False
            if (chunk[2][0] == "VP"):
                if(self.verbPhrase(chunk[2])):
                    pass
                else:
                    return False
            elif (chunk[2][0] == "VA"):
                if(self.verbArgument(chunk[2])):
                    pass
                else:
                    return False
            else:
                return False
        else:
            return False
        
        return True
    
    def nounPhrase(self, chunk):
        try:
            if(chunk[1][1] == "DT"):
                
                if(chunk[2][1] == "NN"):
                    pass
                elif(chunk[2][1] == "JJ"):
                    if(chunk[3][1] == "NN"):
                        pass
                    else:
                        return False
                else:
                    return False
            elif(chunk[1][1] == "PRP"):
                pass
            elif(chunk[1][1] == "PRP$"):
                if(chunk[2][1] == "NN"):
                    pass
                else:
                    return False
            elif(chunk[1][1] == "NNP"):
                pass
            elif(chunk[1][1] == "NN"):
                pass
            elif(chunk[1][1] == "JJ"):
                pass
            else:
                return False
        except IndexError:
                return False
        
        return True
    
    def verbPhrase(self, chunk):
        if(chunk[1][1] == "VBD"):
            pass
        elif(chunk[1][1] == "VBN"):
            pass
        elif(chunk[1][1] == "VBP"):
            if(chunk[2][1] == "RB"):
                if(chunk[3][1] == "VBG"):
                    pass
                else:
                    return False
            else:
                return False
        elif(chunk[1][1] == "VBZ"):
            if (len(chunk) > 2):
                if(chunk[2][1] == "RB"):
                    pass
                else:
                    return False
        elif(chunk[1][1] == "TO"):
            if(chunk[2][1] == "VB"):
                pass
            else:
                return False
        elif(chunk[1][1] == "VB"):
            pass
        else:
            return False
        
        return True
    
    def verbArgument(self, chunk):
        if(chunk[1][0] == "VP"):
            if(self.verbPhrase(chunk[1])):
                if(chunk[2][0] == "NP"):
                    if(self.nounPhrase(chunk[2])):
                        pass
                    else:
                        return False
                else:
                    return False
            else:
                return False
        elif(chunk[1][0] == "VBZ"):
            if(chunk[2][0] == "NP"):
                if(self.nounPhrase(chunk[2])):
                    pass
                else:
                    return False
            else:
                return False
        else:
            return False
        
        return True

if __name__ == '__main__':          
    a = en.sentence.chunk("my favorite things are bacon and tape")
    gram = SentenceGrammar()
    
    print(gram.checkChunks(a))